package dletc.job.job02;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
获取字符串中每一个字母出现的次数。比如输入字符串"aababcabcdabcde",结果为：
a(5)b(4)c(3)d(2)e(1) 提示：使用TreeMap，
将输入的字符串的每个字符作为键到集合中去找值，看返回值。
 */
public class Job02 {

	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		System.out.print("请输入字符串：");
		String num = s.next();
		
		char[] ch = num.toCharArray();
		
		
		Map<Character, Integer> map = new TreeMap<Character, Integer>();
		
			
		for (int i = 0; i < ch.length; i++) {
			if (!map.containsKey(ch[i])) {
				map.put(ch[i], 1);
			}else {
				Integer value = map.get(ch[i]);
				map.put(ch[i], ++value);
			}
			
		}
		
		for(Character c:map.keySet()) {
			System.out.print(c+"("+map.get(c)+")");
		}
		
		

	}

}
